package abaolog

import (
	"github.com/olivere/elastic/v7"
	"github.com/pkg/errors"
	"github.com/sirupsen/logrus"
	"gopkg.in/sohlich/elogrus.v7"
)

// Es config logrus log to es
func Es(esURL []string, esHost, logIndex, userName, userPassword string, logLevel uint32) {

	client, err := elastic.NewClient(elastic.SetURL(esURL...), elastic.SetBasicAuth(userName, userPassword))
	if err != nil {
		logrus.Errorf("config es logger error. %+v", errors.WithStack(err))
	}
	esHook, err := elogrus.NewAsyncElasticHook(client, esHost, logrus.Level(logLevel), logIndex)
	if err != nil {
		logrus.Errorf("config es logger error. %+v", errors.WithStack(err))
	}
	logrus.AddHook(esHook)
}
